package com.resume.view.slidingfragment.fragment;
    
import com.resume.R;
import com.resume.activity.MainActivity;
import com.resume.utils.BitmapUtil;
import com.resume.view.slidingfragment.FragmentControl;

import android.graphics.Bitmap; 
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout; 

/**
 * LeftSlidingFragment
 * @author Zhongdaxia 2013-12-9 17:10:46
 *
 */

public class LeftSlidingFragment extends Fragment {
	
	private FragmentControl mControl;
	
	View view;
	ImageView mImgAvatar;
	LinearLayout mExperience;
	LinearLayout mAbility;
	LinearLayout mOpus;
	LinearLayout mContect;
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.frag_leftsliding, null);
		mControl = FragmentControl.getInstance(getActivity());

		findView();
		setClick();
		Init();

		return view;
	}

	private void findView() {
		mImgAvatar = (ImageView) view.findViewById(R.id.img_avatar);
		mExperience = (LinearLayout) view.findViewById(R.id.ly_experience);
		mAbility = (LinearLayout) view.findViewById(R.id.ly_ability);
		mOpus = (LinearLayout) view.findViewById(R.id.ly_opus);
		mContect = (LinearLayout) view.findViewById(R.id.ly_contect);
	}

	private void setClick() {
		mExperience.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) { 
				if (getActivity() == null)
					return;
				ExperienceFragment fragment = (ExperienceFragment)mControl.getExperienceFragment(); 
				if (getActivity() instanceof MainActivity) {
					MainActivity ra = (MainActivity) getActivity();
					ra.switchContent(fragment);
				}
			}
		});
		mAbility.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) { 
				if (getActivity() == null)
					return;
				AbilityFragment fragment = (AbilityFragment)mControl.getAbilityFragment();
				if (getActivity() instanceof MainActivity) {
					MainActivity ra = (MainActivity) getActivity();
					ra.switchContent(fragment);
				}
			}
		});
		mOpus.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) { 
				if (getActivity() == null)
					return;
				Fragment fragment = mControl.getOpusFragment();
				if (getActivity() instanceof MainActivity) {
					MainActivity ra = (MainActivity) getActivity();
					ra.switchContent(fragment);
				}
			}
		});
		mContect.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) { 
				if (getActivity() == null)
					return;
				Fragment fragment = mControl.getContectFragment();
				if (getActivity() instanceof MainActivity) {
					MainActivity ra = (MainActivity) getActivity();
					ra.switchContent(fragment);
				}
			}
		});
	}

	private void Init() {
		Drawable drawable = getResources().getDrawable(R.drawable.avatar3);
		BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
		Bitmap bitmap = bitmapDrawable.getBitmap();
		mImgAvatar.setImageBitmap(BitmapUtil.getRoundedCornerBitmap(bitmap));
	
	
	
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}
	
 

}
